package tp5;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class CB  extends UnicastRemoteObject implements ICB {
	int codeClient = 0;
	float solde = 0;

	public CB() throws RemoteException {
		super();
	}

	public int getCodeClient() throws RemoteException {
		return codeClient;
	}

	public void depot(float somme) throws RemoteException {
		solde += somme;
	}

	public void retrait(float somme) throws RemoteException {
		solde -= somme;
	}

	public void setCodeClient(int codeClient) throws RemoteException {
		this.codeClient = codeClient;
	}

	public float getSolde() throws RemoteException {
		return solde;
	}

	public void setSolde(float solde) {
		this.solde = solde;
	}

	public void transfert(CB compte, Virement vir) throws RemoteException {
		compte.depot(vir.montant);
		this.retrait(vir.montant);
	}

	public static void main(String[] args) {
		try {		
			Naming.rebind("rmi://localhost:"+PORT+"/"+CB, new CB());
			System.out.println("liaison");
//			ICB cv = (ICB) UnicastRemoteObject.exportObject(new CB(), PORT);
//			Registry registry = LocateRegistry.createRegistry(PORT);
//			registry.rebind("cb", cv);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
